import React, { Component } from 'react'
import PubSub from 'pubsub-js';
export default class Search extends Component {

    state = {
        keyword: ''
    }
    
    render() {
        return (
            <div className="row">
                <div className="col-xs-4 col-xs-offset-8">
                    <div className="input-group">
                        <input type="text" className="form-control" onChange={this.change} value={this.state.keyword} placeholder="Search for..." />
                        <span className ="input-group-btn">
                        <button className ="btn btn-default" type ="button" onClick={this.search}>Go!</button>
                        </span>
                    </div>
                </div>
            </div>
        )
    }

    change = (e) => {
        //
        this.setState({
            keyword: e.target.value
        })
    }

    search = () => {
        //获取关键字
        let {keyword} = this.state;
        //发布出去
        PubSub.publish('hero-name', keyword);
    }
}
